<?php

$server=new swoole\http\server("0.0.0.0",9503);


//swoole会开辟一个协程栈,对协程栈进行初始化
$server->on('request',function(){


    $time=time();
    $swoole_mysql = new Co\MySQL();
    $swoole_mysql->connect([
        'host' => '127.0.0.1',
        'port' => 3306,
        'user' => 'root',
        'password' => 'Qq!990979940',
        'database' => 'test',
    ]);

    //max(mysql(3),mysql(1));
    $swoole_mysql->setDefer(); //延迟收包
    $swoole_mysql->query('select sleep(3)'); //阻塞
    //$swoole_mysql->close();


    $swoole_mysql1 = new Co\MySQL();
    $swoole_mysql1->connect([
        'host' => '127.0.0.1',
        'port' => 3306,
        'user' => 'root',
        'password' => 'Qq!990979940',
        'database' => 'test',
    ]);
    $swoole_mysql1->setDefer();
    $res = $swoole_mysql1->query('select sleep(4)');
    //$swoole_mysql1->close();

    var_dump($swoole_mysql1->recv(),$swoole_mysql->recv());

    //同步代码
    echo  time()-$time.PHP_EOL;

});


$server->start();



